// base
import Taro, { Component } from '@tarojs/taro'
import { View, Text } from '@tarojs/components'
// less
import './index.less'

class CompanyList extends Component {
  static defaultProps = {
    detail: {}
  }
  componentWillMount() {
    // onLoad
  }

  componentDidMount() {
    // onready
  }

  componentWillUnmount() {
    // onUnload
  }

  componentWillReceiveProps(nextprops) {}

  delay(time = 0) {
    return new Promise(resolve => {
      setTimeout(() => {
        resolve()
      }, time)
    })
  }

  chooseCp = index => {
    const { dataSource } = this.props
    const single = dataSource[index]
    this.props.onChooseCompany({
      id: single.id,
      name: single.name
    })
  }

  render() {
    const { dataSource } = this.props
    return (
      <View className="CompanyList_id51415">
        {dataSource.map((data, index) => {
          return (
            <View className="single" onClick={this.chooseCp.bind(this, index)}>
              {data.name}
            </View>
          )
        })}
      </View>
    )
  }
}

export default CompanyList
